import queue
import traceback
from concurrent.futures import ThreadPoolExecutor


class BoundThreadPoolExecutor(ThreadPoolExecutor):
    #对ThreadPoolExecutor 进行重写，给队列设置边界
    def __init__(self, qsize: int = None, *args, **kwargs):
        super(BoundThreadPoolExecutor, self).__init__(*args, **kwargs)
        self._work_queue = queue.Queue(qsize)

def test():
    while 1:
        a = 10
        try:
            s = 1/0
        except:
            print(traceback.format_exc())
            continue

    print('done')

if __name__ == '__main__':
    pool = BoundThreadPoolExecutor(qsize=18, max_workers=18)
    pool.submit(test)